/* ==============================================================================
 * 创 建 者：LYT
 * 创建日期：2018-03-14	
 * 功能描述：注册

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ==============================================================================*/

//根据会员ID获取账号
var getNameUrl = baseUrl + 'DefaultF/GetMemberInfo';
//注册接口
var registerUrl = baseUrl + 'DefaultF/RegeditSumbit';
//银行列表
var getBankListUrl = baseUrl + 'common/GetBankList';
//密保问题列表
var getQuestionListUrl = baseUrl + 'common/GetQuestionList';
//手机验证码
var getRegisterCodeUrl = baseUrl + 'DefaultF/RegisterCode';

var getValidateCode = baseUrl + 'common/GetValidateCode';

var recommendOID = getURLParameter("recommendOID");
var vu;



$(function(){
	mui.init()
	initVue();
	if(recommendOID && recommendOID != "null"){
		vu.getName();
	}
});

function initVue(){
	vu = new Vue({
		el: '#content',
		data: {
			RecommendName :'',
			Name :'',
			NiName :'',
			ParentName :'',
			LocationIndex :'',
			NewPassword :'',
			ConNewPassword :'',
			SecNewPassword :'',
			ConSecNewPassword :'',
			BankName :'',
			SubBranchBank :'',
			CardName :'',
			CardNumber :'',
			Tel :'',
			Question :'',
			Answer :'',
			ReportName : '',//报单中心
			
			IdentityCard:'',
			QuestionList:[],
			BankList:[],
			loadding: false,
			
			Code : '',
			codeImg : '',
			
			validCode: true,
			VerificationCode:'',
		},
		mounted: function() {
			this.getCode();
			this.getBankList();
			this.getQuestionList();
			
			//this.getVerfication();
		},
		methods: {
			
			getCode: function () {
                common.post(getValidateCode, {},"", function (r) {
//              	console.log(r.Data.ImageUrl);
                    vu.codeImg = r.Data.ImageUrl;
                })
            },
			getName : function(){
				common.post(getNameUrl, {name : recommendOID}, '', function(r) {
					if(r.ErrorCode == 0) {
						vu.RecommendName = r.Data.Name;
						vu.ParentName = r.Data.Name;
						$("#Referee").attr("readonly",true);
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			register: function() {
				var _this = this;
				var myreg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,8}$/;
				if(!this.Name) {
					mui.toast('请输入账号');
					return;
				};
				if(!myreg.test(this.Name)) {
					mui.toast('账号格式不正确');
					return;
				};
				if(!this.Tel) {
					mui.toast('请输入手机号');
					return;
				};
				if(!this.VerificationCode) {
					mui.toast('请输入短信验证码');
					return;
				};
				if(!this.RecommendName){
					mui.toast('请输入推荐人');
					return;
				}
//				if(!this.NiName) {
//					mui.toast('请输入昵称');
//					return;
//				};
				if(!this.NewPassword) {
					mui.toast('请输入登陆密码');
					return;
				};
				if(!this.ConNewPassword) {
					mui.toast('请再次输入登陆密码');
					return;
				};
				if(this.NewPassword != this.ConNewPassword) {
					mui.toast('登陆密码输入不一致');
					return;
				};
//				if(!this.SecNewPassword) {
//					mui.toast('请输入安全密码');
//					return;
//				};
//				if(!this.ConSecNewPassword) {
//					mui.toast('请再次输入安全密码');
//					return;
//				};
//				if(this.SecNewPassword != this.ConSecNewPassword) {
//					mui.toast('两次安全密码输入不一致');
//					return;
//				};
				
				vu.loadding = true;
				var param = {
					RecommendName : _this.RecommendName,
					Name : _this.Name,
//					NiName : _this.NiName,
					NewPassword : _this.NewPassword,
					ConNewPassword : _this.ConNewPassword,
//					SecNewPassword : _this.SecNewPassword,
//					ConSecNewPassword : _this.ConSecNewPassword,
					Tel : _this.Tel,
					VerificationCode:_this.VerificationCode,
				}
				common.post(registerUrl, param, '', function(r) {
					vu.loadding = false;
					if(r.ErrorCode == 0) {
						mui.toast('注册成功!即将跳转至下载页面..');
						setTimeout(function () {
						    location.href = 'http://j9uoz.gylb58.com/downpage/f6b13302e21f4d65';
						}, 1500);

					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getQuestionList : function(){
				var _this = this;
				common.post(getQuestionListUrl, {}, '', function(r) {
					if(r.ErrorCode == 0) {
						_this.QuestionList = r.Data.List;
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getBankList : function(){
				var _this = this;
				common.post(getBankListUrl, {}, '', function(r) {
					if(r.ErrorCode == 0) {
						_this.BankList = r.Data.List;
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getTelphoneCode: function(e) {
				var _this = this;
				var code = $(e.target);
				if(!this.Tel) {
					mui.toast('请输入手机号');
					return;
				} 
				if(!this.Code) {
					mui.toast('请输入图形验证码');
					return;
				} 
					var time = 60;
					common.post(getRegisterCodeUrl, {Tel: _this.Tel,VerifyCode:_this.Code}, 'json', function(r) {
						if(r.ErrorCode == 0) {
							mui.toast(r.ErrorMsg);
							if(_this.validCode) {
								if(r.Data.RemainingTime){
									time = r.Data.RemainingTime;
								}
								_this.validCode = false;
								var t = setInterval(function() {
									time--;
									code.text(time + "秒");
									if(time == 0) {
										clearInterval(t);
										code.text("重新获取");
										_this.validCode = true;
									}
								}, 1000)
							}
						} else {
							mui.toast(r.ErrorMsg);
						}
					})
			},
		}
	})
}




/*
	VerificationCode: '',
	VerifyCode: '',
	validCode: true,
	ImageUrl: '',
	
	getTelphoneCode: function(e) {
		var _this = this;
		var code = $(e.target);
		if(!this.Tel) {
			mui.toast('请输入手机号');
			return;
		} else {
			var time = 60;
			common.post(RegisterCode, {Tel: _this.Tel}, 'json', function(r) {
				if(r.ErrorCode == 0) {
					if(_this.validCode) {
						_this.validCode = false;
						var t = setInterval(function() {
							time--;
							code.text(time + "秒");
							if(time == 0) {
								clearInterval(t);
								code.text("重新获取");
								_this.validCode = true;
							}
						}, 1000)
					}
				} else {
					mui.toast(r.ErrorMsg);
				}
			})
		}
	},
	getVerfication: function() {
		common.post(codeUrl, {}, 'json', function(r) {
			if(r.ErrorCode == 0) {
				vu.ImageUrl = r.Data.ImageUrl;
			} else {
				mui.toast(r.ErrorMsg);
			}
		})
	}
	
 */